backtracking_retractall([H|T]):- retract(H), backtracking_retractallr(T).
backtracking_retractallr([H|T]):- retract(H), backtracking_retractallr(T).
backtracking_retractallr([]).
backtracking_retractall([H|T]):- asserta(H), backtracking_retractalla(T).
backtracking_retractalla([H|T]):- asserta(H), backtracking_retractalla(T).
backtracking_retractalla([]) :- fail.

categories([shoes, sweaters, blouses, tops, trousers, tshirts, skirts, sportshoes, dresses, jackets, suits, overcoats, boots]).

category_filter(general):- !,category_filter_exclude([tshirts]).

%category_filter(dresses):- !, category_filter_exclude([boots]).

% Caso exclude
%attributes_filter(dresses,Name,Color,Length,Season,Extra):- !, cloth(dresses, Name,Color,Length,Season,Extra,Position),Color == blue,Length == long, backtracking_retractall([attributes_filter(boots,_,_,_,_,_)]).

%Caso include
attributes_filter(dresses,Name,Color,Length,Season,Extra):- !, cloth(dresses, Name,Color,Length,Season,Extra,Position),Color == blue,Length == long, backtracking_retractall([attributes_filter(shoes,_,_,_,_,_),attributes_filter(sweaters,_,_,_,_,_),attributes_filter(blouses,_,_,_,_,_),attributes_filter(tops,_,_,_,_,_),attributes_filter(trousers,_,_,_,_,_),attributes_filter(skirts,_,_,_,_,_),tributes_filter(sportshoes,_,_,_,_,_),attributes_filter(jackets,_,_,_,_,_),attributes_filter(suits,_,_,_,_,_)]).



attributes_filter(dresses,_,_,_,_,_).
attributes_filter(boots,_,_,_,_,_).
attributes_filter(shoes,_,_,_,_,_).
attributes_filter(sweaters,_,_,_,_,_).
attributes_filter(blouses,_,_,_,_,_).
attributes_filter(tops,_,_,_,_,_).
attributes_filter(trousers,_,_,_,_,_).
attributes_filter(skirts,_,_,_,_,_).
attributes_filter(sportshoes,_,_,_,_,_).
attributes_filter(jackets,_,_,_,_,_).
attributes_filter(suits,_,_,_,_,_).
attributes_filter(overcoats,_,_,_,_,_).

%cloth(CATEGORY, NAME, COLOR, LENGTH, SEASON, EXTRA, POSITION)
% POSITION = [overall, coat, top, bottom, footwear]
cloth(dresses, dress1, darkBlue, short, summer,[pois],overall).
cloth(dresses, dress2, grey, long, winter,[patterned],overall).
cloth(dresses, dress3, orange, medium, summer,[],overall).
cloth(dresses, dress4, blue, long, winter,[stripes],overall).
cloth(dresses, dress5, black, short, midseason,[studs],overall).

cloth(overcoats,overcoat1,black,medium,winter,[],coat).
cloth(overcoats,overcoat2,cream,long,winter,[chest],coat).
cloth(overcoats,overcoat3,black,short,winter,[],coat).

cloth(jackets,jacket1,blue,medium,midseason,[],coat).
cloth(jackets,jacket2,black,short,midseason,[],coat).
cloth(jackets,jacket3,jeans,short,midseason,[],coat).

cloth(sweaters,sweater1,yellow,long,winter,[buttons],top).
cloth(sweaters,sweater2,pink,long,winter,[pois],top).
cloth(sweaters,sweater3,green,long,winter,[cardigan,buttons],top).
cloth(sweaters,sweater4,brown,long,winter,[],top).
cloth(sweaters,sweater5,white,long,winter,[],top).

cloth(blouses,blouse1,fuchsia,long,midseason,[buttons],top).
cloth(blouses,blouse2,violet,medium,midseason,[zip],top).
cloth(blouses,blouse3,navy,long,midseason,[design],top).
cloth(blouses,blouse4,khaki,medium,midseason,[ribbon,stripes],top).
cloth(blouses,blouse5,coral,long,midseason,[animalprint],top).

cloth(tops,top1,beige,long,midseason,[],top).
cloth(tops,top2,white,short,summer,[],top).
cloth(tops,top3,salmon,medium,midseason,[pois],top).
cloth(tops,top4,peach,short,summer,[],top).
cloth(tops,top5,lime,long,midseason,[],top).

cloth(tshirts,tshirt1,black,short,summer,[ribbon],top).
cloth(tshirts,tshirt2,olive,short,summer,[lace],top).
cloth(tshirts,tshirt3,cream,short,summer,[ethnic],top).
cloth(tshirts,tshirt4,red,short,summer,[picture],top).
cloth(tshirts,tshirt5,beige,short,summer,[ribbon,lace],top).

cloth(trousers,trousers1,jeans,long,midseason,[studs],bottom).
cloth(trousers,trousers2,black,long,midseason,[suit],bottom).
cloth(trousers,trousers3,darkBlue,long,summer,[linen,flower],bottom).
cloth(trousers,trousers4,red,long,midseason,[stretch],bottom).
cloth(trousers,trousers5,brown,long,winter,[skinny],bottom).

cloth(skirts,skirt1,darkGrey,medium,midseason,[pencil],bottom).
cloth(skirts,skirt2,black,long,midseason,[maxi],bottom).
cloth(skirts,skirt3,green,short,summer,[stretch],bottom).
cloth(skirts,skirt4,blue,short,winter,[],bottom).
cloth(skirts,skirt5,jeans,short,allseason,[],bottom).

cloth(suits,suit1,darkGrey,long,midseason,[],overall).
cloth(suits,suit2,black,long,winter,[],overall).

cloth(shoes,shoes1,black,high,winter,[zip],footwear).
cloth(shoes,shoes2,grey,high,allseasons,[],footwear).
cloth(shoes,shoes3,red,medium,allseasons,[],footwear).
cloth(shoes,shoes4,beige,flat,summer,[studs],footwear).
cloth(shoes,shoes5,brown,flat,midseason,[ballet],footwear).

cloth(boots,boots1,black,high,winter,[],footwear).
cloth(boots,boots2,brown,medium,midseason,[],footwear).

cloth(sportshoes,sportshoes1,white,flat,summer,[],footwear).
cloth(sportshoes,sportshoes2,black,flat,allseasons,[],footwear).


%Da mettere via codice=================

% Mette in Z le categorie da eliminare date nel primo parametro le categorie da mantenere,
% il secondo parametro contiene tutte le categorie.
delete_sub_list([H|T],L,Z):- delete(H,L,FL), delete_sub_list(T,FL,Z).
delete_sub_list([],L,L).

subListPos([H|T],L):- member(H,L), subListPos(T,L).
subListPos([_|T],L):- subListPos(T,L).
subListPos(_,L).
subListNeg([H|T],L):- not(member(H,L)), subListNeg(T,L).
subListNeg([_|T],L):-subListNeg(T,L).
subListNeg(_,L).

%exclude
category_filter_exclude([H|T]) :- retractall(cloth(H, B, C, D, E, F, G)), category_filter_exclude(T).
%category_filter_exclude([H|T]):- category_filter_exclude(T).
category_filter_exclude([]).

%include _only
retract_categories([H|T]) :- retractall(cloth(H,_,_,_,_,_,_)),  retract_categories(T).
retract_categories([]).
category_filter_include(IncludeList,AllCategories):-  	delete_sub_list(IncludeList,AllCategories,CatList), 
							retract_categories(CatList).
							
category_filter(_).


createOutfit(Season, N1, N2, N3, P1, P2, P3) :-	category_filter(general),
					cloth(C1, N1, CO1, L1, Season, E1, P1), 
					cloth(C2, N2, CO2, L2, Season, E2, P2), 
					cloth(C3, N3, CO3, L3, Season, E3, P3),
					%category_filter(C1),
					%category_filter(C2),
					%category_filter(C3),
					attributes_filter(C1, N1, CO1, L1, Season, E1),
					attributes_filter(C2, N2, CO2, L2, Season, E2),
					attributes_filter(C3, N3, CO3, L3, Season, E3).
					
createOutfit2(Season, N1, N2, N3, P1, P2, P3) :-	category_filter(general),
					cloth(C1, N1, CO1, L1, Season, E1, P1), 
					cloth(C2, N2, CO2, L2, Season, E2, P2), 
					cloth(C3, N3, CO3, L3, Season, E3, P3).



